package indi.flynn.zhouyi.log.enums;

/**
 * 流程节点枚举
 * 每个流程节点都应该在此枚举中定义，并且有唯一的code
 */
public enum BizFlowNodeEnum {

    /**
     * 用户注册流程节点
     */
    USER_VALIDATE("USER_VALIDATE", "用户信息校验"),
    USER_CREATE("USER_CREATE", "创建用户"),
    USER_NOTIFY("USER_NOTIFY", "用户通知"),

    /**
     * 订单创建流程节点
     */
    ORDER_VALIDATE("ORDER_VALIDATE", "订单信息校验"),
    ORDER_STOCK_CHECK("ORDER_STOCK_CHECK", "库存检查"),
    ORDER_SAVE("ORDER_SAVE", "保存订单"),

    /**
     * 支付处理流程节点
     */
    PAYMENT_VALIDATE("PAYMENT_VALIDATE", "支付信息校验"),
    PAYMENT_PROCESS("PAYMENT_PROCESS", "处理支付"),
    PAYMENT_CALLBACK("PAYMENT_CALLBACK", "支付回调");

    /**
     * 节点编码
     */
    private final String code;

    /**
     * 节点描述
     */
    private final String desc;

    BizFlowNodeEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 根据code获取枚举
     */
    public static BizFlowNodeEnum getByCode(String code) {
        if (code == null) {
            return null;
        }

        for (BizFlowNodeEnum nodeEnum : values()) {
            if (nodeEnum.getCode().equals(code)) {
                return nodeEnum;
            }
        }
        return null;
    }
}

